package FrequencyFinder;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class FrequencyFinder {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        Map<Integer, Integer> countMap = new HashMap<>();
        System.out.println("请输入一系列整数，以0结束输入：");
        while(true)
        {
            int number = sc.nextInt();
            if(number == 0)
            {
                break;
            }
            countMap.put(number, countMap.getOrDefault(number, 0) + 1);
        }

        int maxFrequency = 0;
        for(int frequency : countMap.values())
        {
            if(frequency > maxFrequency)
            {
                maxFrequency = frequency;
            }
        }

        System.out.println("出现频率最高的数字有：");
        for(Map.Entry<Integer, Integer> entry : countMap.entrySet())
        {
            if(entry.getValue() == maxFrequency)
            {
                System.out.print(entry.getKey() + " ");
            }
        }
        System.out.println();
    }
}
